home *** CD-ROM | disk | FTP | other *** search
- This material is placed in the public domain by its author, William Couture.
- Copyright (c) 1986 by DDI. All Rights Reserved.
-
-
- CHARACTER GRAPHICS ROUTINES AVAILABLE
-
- GENERAL NOTES:
- All routines work in 320 x 200 4-color mode or 640 x 200 mode.
- COLOR is an integer between 0 and 3, inclusive, for 320 x 200 mode,
- and between 0 and 1, inclusive, for 640 x 200 mode (0 = background).
- Adding 128 to the color will XOR draw the character instead of
- plotting it. This will allow you to place characters on top of
- already drawn graphics screens without leaving holes in the picture.
- All the regular graphics routines are also available.
- CROW (Character ROW) is an integer between 1 and 25, inclusive.
- CCOL (Character COL) is an integer between 1 and 40, inclusive, for
- 320 x 200 mode, and between 1 and 80 for 640 x 200 mode.
- Do not let ANY routine draw anything beyond a screen edge.
- Character graphics can only be displaed in the spaces where normal
- characters would be on a 25 x 40 screen for 320 x 200 mode,
- and in the spaces where charcters would be on a 25 x 80
- screen for 640 x 200 mode.
- WCHAR is an integer between 0 and 127, inclusive. This is the index to
- the desired graphics character.
- CSHAPES is the name of an array which contains the character shapes.
-
-
-
-
-
- TYPE DEFINITIONS AND VARIABLES:
- Type CHARSET is a 1024 element of byte, which holds the character images
- being used. The definition is ARRAY[0..1023] OF BYTE with the array
- base at 0 for correspondence with machine language references.
-
- Type FILENAME is simply an 80 character string, used to pass a filename
- to the readcset and writecset functtions. Its definition is STRING[80]
-
- Type CHARMESSAGE is defined to pass a "string" of graphics characters to
- the procedures described below. It is an array of integers, to bypass
- the problems with signed and unsigned bytes/chars. Its definition is
- ARRAY[0..79] OF INTEGER
-
- The variables COLDSEG and COLDADDR stand for Character OLD SEGment and
- Character OLD ADDress, respectively, and are used to store the previous
- values of the character set pointer. They are not needed if the GETVECT
- and RESTOREVECT procedures are not used, and the names may be changed to
- suit your tastes.
-
-
-
-
-
-
-
-
- ROUTINES:
-
- function readcset(var cshapes:charset; fname:filename)
- Try to read the character set named filename into memory. The routine
- will return -1 if fname cannot be found, else it will return 1.
-
- example: errno := readcset(shapes,'myset.chr');
- if errno = -1 then
- writeln('Error - character set not found.');
- else
- run_program;
-
-
-
-
- function writecset(var cshapes:charset; fname:filename)
- Write the current character set from memory to a disk file named fname.
- The routine returns a -1 if the file cannot be created, else it returns
- a 1.
-
- example: errno := writecset(shapes,'c:\stuff\saved.chr');
- if errno = -1 then
- writeln('Error - cannot open file to write character set.');
- else
- writeln('Character set saved.');
-
-
-
- procedure getvect
- Save the system's graphics character set pointer. This should only be
- called once, before the start of using character graphics. It also has
- a companion routine, RESTOREVECT.
-
-
-
-
- procedure restorevect
- Restore the system's graphics character set pointer. It can be called
- any number of times, but getvect MUST HAVE BEEN CALLED FIRST.
-
-
-
- procedure setvect(var cshapes:charset)
- Set the system to display your graphics character set. This can be called
- any number of times, to display differenct character sets.
-
-
-
-
-
- procedure setbit(var cshapes:charset; wchar,row,col:integer)
- row and col are integers from 0 to 7, inclusive
- Set the bit at row,col in WCHAR to ON.
-
-
-
- procedure clearbit(var cshapes:charset; wchar,row,col:integer)
- row and col are integers from 0 to 7, inclusive
- Set the bit at row,col in WCHAR to OFF.
-
-
-
- procedure xorbit(var cshapes:charset; wchar,row,col:integer)
- row and col are integers from 0 to 7, inclusive
- Set the bit at row,col in WCHAR to the opposite of its current state.
-
-
-
- procedure zerochar(var cshapes:charset; wchar:integer)
- Set all bits in WCHAR to OFF.
-
-
-
- procedure fillchar(var cshapes:charset; wchar:integer)
- Set all bits in WCHAR to ON.
-
-
-
- procedure inversechar(var cshapes:charset; wchar:integer)
- Set all bits in WCHAR to the opposite of their current state.
-
-
-
- procedure copychar(var cshapes:charset; fromchar,intochar:integer)
- fromchar and intochar are two examples of WCHAR
- Make the graphics character intochar the same as fromchar.
-
-
-
- procedure horizflip(var cshapes:charset; wchar:integer)
- Mirror WCHAR about its horizontal axis.
-
-
-
- procedure vertflip(var cshapes:charset; wchar:integer)
- Mirror WCHAR about its vertical axis.
-
-
-
- procedure exchangerc(var cshapes:charset; wchar:integer)
- Exchange rows and columns in WCHAR.
-
-
-
- procedure shiftdown(var cshapes:charset; wchar:integer)
- Move the picture in WCHAR down 1 row. The bottom row is lost and the
- top row is set to blank.
-
-
-
- procedure shiftup(var cshapes:charset; wchar:integer)
- Move the picture in WCHAR up 1 row. The top row is lost and the bottom
- row is set to blank.
-
-
-
- procedure shiftleft(var cshapes:charset; wchar:integer)
- Move the picture in WCHAR left 1 column. The left column is lost and
- the right column is set to blank.
-
-
-
- procedure shiftright(var cshapes:charset; wchar:integer)
- Move the picture in WCHAR right 1 column. The right column is lost and
- the left column is set to blank.
-
-
-
- procedure rotatedown(var cshapes:charset; wchar:integer)
- Move the picture in WCHAR down 1 row. The bottom row wraps into the top
- row.
-
-
-
- procedure rotateup(var cshapes:charset; wchar:integer)
- Move the picture in WCHAR up 1 row. The top row wraps into the bottom
- row.
-
-
-
- procedure rotateleft(var cshapes:charset; wchar:integer)
- Move the picture in WCHAR left 1 column. The left column wraps into
- the right column.
-
-
-
- procedure rotateright(var cshapes:charset; wchar:integer)
- Move the picture in WCHAR right 1 column. The right column wraps into
- the left column.
-
-
-
- procedure grchar(wchar,color:integer)
- Plot the graphics char WCHAR at the current cursor position in COLOR.
- The routine may be modified so that adding 128 ($80 in hex) to the
- WCHAR value will draw the normal ASCII character instead of the
- graphics character. See the comments in PCHR.I for details.
- Adding 128 ($80 in hex) to the color will XOR draw the character,
- placing it on top of the current screen image.
-
-
-
- procedure gratchar(crow,ccol,wchar,color:integer)
- Plot the graphics char WCHAR at CROW,CCOL in COLOR.
- The routine may be modified so that adding 128 ($80 in hex) to the
- WCHAR value will draw the normal ASCII character instead of the
- graphics character. See the comments in PCHR.I for details.
- Adding 128 ($80 in hex) to the color will XOR draw the character,
- placing it on top of the current screen image.
-
-
-
- procedure printbanner(crow,ccol:integer; msg:charmessage; length,color:integer)
- MSG is an array of integers which
- contains the WCHAR codes for the banner
- LENGTH is the number of elements in MSG
- Move the cursor to CROW,CCOL and display the LENGTH graphics characters
- from MSG across the screen in COLOR. Please note that adding 128 ($80
- in hex) to the color will XOR draw the characters, placing them on top
- of the current screen image.
-
-
-
-
- procedure bannerleft(var cshapes:charset; var msg:charmessage; length:integer)
- MSG is an array of integers which
- contains the WCHAR codes for the banner.
- LENGTH is the number of elements in MSG
- Treat LENGTH elements of MSG as one extended graphics character and
- rotate it left 1 column. The column rolled off the left is wrapped back
- on the right.
-
-
-
- procedure bannerright(var cshapes:charset; var msg:charmessage; length:integer)
- MSG is an array of integers which contains
- the WCHAR codes for the banner.
- LENGTH is the number of elements in MSG
- Treat LENGTH elements of MSG as one extended graphics character and
- rotate it right 1 column. The column rolled off the right is wrapped back
- to the left.
-
-
-
- procedure bannerup(var cshapes:charset; var msg:charmessage; length:integer)
- MSG is an array of integers which contains
- the WCHAR codes for the banner.
- LENGTH is the number of elements in MSG
- Move LENGTH elements of MSG up 1 row. The row rotated off the top
- wraps back to the bottom. Note that any character may be individually
- scrolled via the rotatexxxx() procedures above.
-
-
-
- procedure bannerdown(var cshapes:charset; var msg:charmessage; length:integer)
- MSG is an array of integers, which contains
- the WCHAR codes for the banner.
- LENGTH is the number of elements in MSG
- Move LENGTH elements of MSG down 1 row. The row rotated off the
- bottom wraps back to the top. Note that any character may be individually
- scrolled via the rotatexxxx() functions above.
-
-
- example:
-
- program example1;
-
- {$Ipchr.i } { Include the character routines. THE SPACES AFTER THE .i }
- { EXTENSION MUST BE INCLUDED }
-
- var
- shapes : charset; { the array to hold the character shapes }
- message : charmessage; { the array to hold the message to be plotted }
- errno : integer; { to hold the return value from READCSET }
- i,m : integer; { loop indices }
-
- begin { main program }
- errno := readcset(shapes,'alpha.chr');
- { read the character set }
- if errno <> -1 then { if all ok }
- begin
- graphcolormode; { set to 320 x 200 graphics }
- message[0] := 65; { graphics character 65 }
- message[1] := 67; { etc. }
- message[2] := 69;
- getvect; { save the system vector }
- setvect(shapes); { and insert our own }
- printbanner(2,5,message,2,1);
- { print the message in color 1, cyan }
- { note that this displays only the first 2 }
- { characters, so the 3rd is "hidden" }
- for i := 1 to 8*3*20 do
- { rotate through all 8 columns of the 3 chars }
- { 20 times }
- begin
- for m := 1 to 1500 do ;
- { waste a little time }
- bannerleft(shapes,message,3);
- { rotate all left so all characters take turns
- being hidden }
- printbanner(2,5,message,2,1);
- { and display it again }
- end;
- for m := 0 to 30000 do ;
- { one last time delay }
- restorevect; { put the system vector back }
- textmode; { turn the graphics off }
- end; { end of the if }
- end. { end of the program }
-
-
-
-
-
-
-
-
- procedure printcolumn(crow,ccol:integer; msg:charmessage; length,color:integer)
- MSG is an array of integers which contains
- the WCHAR codes for the column.
- LENGTH is the number of elements in MSG
- Move the cursor to CROW,CCOL and display the LENGTH graphics chatacters
- from MSG down the screen in COLOR. Please note that adding 128 ($80
- in hex) to the color will XOR draw the characters, placing them on top
- of the current screen image.
-
-
-
- procedure columnup(var cshapes:charset; var msg:charmessage; length:integer)
- MSG is an array of integers which contains
- the WCHAR codes for the column.
- LENGTH is the number of elements in MSG.
- Treat LENGTH elements of MSG as one extended graphics character and
- rotate it 1 row up. The row that rolls off the top wraps to the bottom.
-
-
-
- procedure columndown(var cshapes:charset; var msg:charmessage; length:integer)
- MSG is an array of integers which contains
- the WCHAR codes for the column.
- LENGTH is the number of elements in MSG.
- Treat LENGTH elements of MSG as on extended graphics character and
- rotate it 1 row down. The row that rolls off the bottom wraps to the top.
-
-
-
- procedure columnleft(var cshapes:charset; var msg:charmessage; length:integer)
- MSG is an array of integers which contains
- the WCHAR codes for the column.
- LENGTH is the number of elements in MSG.
- Move LENGTH elements of MSG left 1 column. The column rotated off the
- left wraps to the right. Note that any element of the column may be
- scrolled by the rotatexxxx() functions above.
-
-
-
- procedure columnright(var cshapes:charset; var msg:charmessage; length:integer)
- MSG is an array of integers which contains
- the WCHAR codes for the column.
- LENGTH is the number of elements in MSG.
- Move LENGTH elements of MSG right 1 column. The column rotated off
- the right wraps to the left. Note that any element of the column may be
- scrolled by the rotatexxxx() functions above.
-
-
-
-
-
-
- example:
-
-
-
- program examp2;
-
- {$Ipchr.i } { The include file that contains the definitions of the }
- { character graphics routines. THE SPACES AFTER THE .i }
- { EXTENSION MUST BE INCLUDED }
-
- var
- shapes : charset;
- window1,window2,window3 : charmessage;
- { Note: if you want to save space, the definition }
- { of CHARMESSAGE can be changed to a smaller array }
- i,m,n,p,errno,delay,delta : integer;
- { loop indices and such }
- ch : char; { a character for user response }
-
- begin { main program }
- errno := readcset(shapes,'slotmchn.chr');
- { read the character set }
- if errno <> -1 then { if all is ok }
- begin
- graphcolormode; { set 320 x 200 graphics }
- gotoxy(1,20);
- writeln('Press the Space Bar to roll again');
- { let the user know what to do }
- getvect; { save the system vector }
- setvect(shapes); { and put in our own }
- for i := 0 to 4 do { set up the bells and whistles (and cherries }
- begin { and lemons and... }
- window1[i] := i; { use these characters }
- window2[i] := i+10;
- window3[i] := i+20;
- end;
- for i := 0 to 4 do
- begin
- copychar(shapes,window1[i],window2[i]);
- { copy the pictures from window1 to window 2 }
- copychar(shapes,window1[i],window3[i]);
- { and window 3 }
- end;
- repeat { now do the display }
- i := 8*(random(11)+5);
- { spin window 1 5 to 15 times (8 rows/char) }
- m := i+8*(random(6)+5);
- { window 2 spins a little longer }
- n := m+8*(random(6)+5);
- { and window 3 longer yet }
- printcolumn(5,10,window1,1,3);
- { display the initial characters }
- printcolumn(5,15,window2,1,3);
- printcolumn(5,20,window3,1,3);
- { Note: for displaying 1 character, gratchar }
- { could also be used. }
- { e.g. gratchar(5,x,windowx[0],3) }
- delay := 0; { start off fast }
- repeat
- if i <> 0 then { each window rolls its own number of times }
- begin
- columndown(shapes,window1,5); { roll window }
- i := i-1; { count it }
- if i = 0 then
- delay := delay+50;
- { if this window is not going to roll }
- { anymore, make up for the processing }
- { time lost not updating it }
- end;
- if m <> 0 then { this looks just like the previous one }
- begin
- columndown(shapes,window2,5);
- m := m-1;
- if m = 0 then
- delay := delay+50;
- end;
- columndown(shapes,window3,5);
- n := n-1; { the 3rd window needs no fancy processing, as we }
- { know it will be spinning to the very end }
- for delta := 0 to delay do ; { waste a little time }
- delay := delay+10; { waste a little more time next time }
- printcolumn(5,10,window1,1,3); { update the windows }
- printcolumn(5,15,window2,1,3);
- printcolumn(5,20,window3,1,3);
- until n = 0; { end of inner repeat loop }
- read(kbd,ch); { get the users response }
- until ch <> ' '; { and repeat until it is not a space }
- restorevect; { put the system vector back }
- textmode; { restore the regular screen }
- end; { of the if statement }
- end. { end of the program }
-